﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media;

namespace FatoryTool
{
    class Pipe : UserControl
    {
        public RotateCenter RotateCenterPoint;
        public PointF StartPoint { get; set; }

        public double Angle { get; set; }
        public double PipeLength
        {
            get { return this.Width; }
            set { this.Width = value; }
        }
        public double PipeDiameter
        {
            get { return this.Height; }
            set { this.Height = value; }
        }
        public enum RotateCenter
        {
            LeftTop,LeftBottom,RightTop,RightBottom
        }
        public Pipe(RotateCenter rotateCenterPoint,PointF startPoint, double angle, double pipeDiameter,double pipeLength)
        {
            this.RotateCenterPoint = rotateCenterPoint;
            this.StartPoint = startPoint;
            this.Angle = angle;
            this.PipeDiameter = pipeDiameter;
            this.PipeLength = pipeLength;
            this.Width = pipeLength;
            this.Height = pipeDiameter;
            ResetPostion();
        }

        public void ResetPostion()
        {
            double CenterX = 0, CenterY = 0;
            if (this.RotateCenterPoint == RotateCenter.LeftTop)
            {
                this.Margin = new System.Windows.Thickness(this.StartPoint.X, this.StartPoint.Y, 0, 0);
                CenterX = 0;
                CenterY = 0;
            }
            else if (this.RotateCenterPoint == RotateCenter.LeftBottom)
            {
                this.Margin = new System.Windows.Thickness(this.StartPoint.X, this.StartPoint.Y - this.PipeDiameter, 0, 0);
                CenterX = 0;
                CenterY = this.PipeDiameter;
            }
            else if (this.RotateCenterPoint == RotateCenter.RightTop)
            {
                this.Margin = new System.Windows.Thickness(this.StartPoint.X - this.PipeLength, this.StartPoint.Y, 0, 0);
                CenterX = this.PipeLength;
                CenterY = 0;
            }
            else if (this.RotateCenterPoint == RotateCenter.RightBottom)
            {
                this.Margin = new System.Windows.Thickness(this.StartPoint.X - this.PipeLength, this.StartPoint.Y - this.PipeDiameter, 0, 0);
                CenterX = this.PipeLength;
                CenterY = this.PipeDiameter;
            }
            RotateTransform rotateTransform = new RotateTransform(this.Angle, CenterX, CenterY);
            //this.LayoutTransform = rotateTransform;
            this.RenderTransform = rotateTransform;
        }

    }
}
